<template>
  <div class="page-main" v-title data-title="编辑物料领用权限维护表">
    <home-nav :userData="userinfo"></home-nav>
    <div class="container">
      <div class="head-content">
        <span class="bold-font">编辑物料领用权限维护表</span>
        <div class="btn-line">
          <a-button class="hte-btn add-btn" type="primary" @click="handleSave('handleSave')">保存</a-button>
        </div>
      </div>
      <div class="content">
        <a-form-model
          ref="ruleForm"
          :model="powers"
          :rules="rules"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <section>
            <div class="section-header">基础信息</div>
            <a-row :gutter="24">
              <a-col :span="12">
                <a-form-model-item label="费用类型:" prop="type">
                  <a-select
                    v-model="powers.type"
                    :default-active-first-option="false"
                    :show-arrow="false"
                    :filter-option="false"
                    :not-found-content="null"
                    allowClear
                  >
                    <a-select-option v-for="item in typeOptions" :key="item.code" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item label="费用号支出号:" prop="costNumber">
                  <a-input v-model="powers.costNumber" />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="12">
                <a-form-model-item label="项目名称" prop="projectName">
                  <a-input v-model="powers.projectName" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item label="项目负责人:" prop="projectManager">
                  <UserInputSelector
                    :username.sync="powers.projectManagerId"
                    :realname.sync="powers.projectManager"
                    multiple="multiple"
                    placeholder="请选择"
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-model-item label="领料人:" prop="consumUser">
                  <UserInputSelector
                    :username.sync="powers.consumUserId"
                    :realname.sync="powers.consumUser"
                    multiple="multiple"
                    placeholder="请选择"
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
          </section>
        </a-form-model>
      </div>
    </div>
  </div>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
export default {
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
  },
  data() {
    return {
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ContractReportInfo',
      },
      urls: {
        info: '/materials/powers/info',
        edit: '/materials/powers/edit',
      },
      typeOptions: [
        { code: '1', name: '成本中心' },
        { code: '2', name: 'WBS号' },
      ],
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
      rules: {
        costNumber: [{ required: true, message: '请输入', trigger: 'blur' }],
        type: [{ required: true, message: '请选择', trigger: 'blur' }],
      },
      id: '',
      powers: { costNumber: '1' },
      permission: [],
    }
  },
  computed: {},
  mounted() {},
  methods: {
    fetchPowers(id) {
      this.id = id
      getAction(this.urls.info + '/' + id).then((res) => {
        if (res.success) {
          this.powers = res.result
        } else {
          this.$message.error('获取物料领用权限维护表信息失败:' + res.message)
        }
      })
    },
    handleSave() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          postAction(this.urls.edit, this.powers).then((res) => {
            if (res.success) {
              this.powers = res.result
              this.$message.success('保存成功')
               if (this.$route.path.startsWith('/materials/powers/add')) {
            this.$router.push('/materials/powers/edit/' + this.infrastructure.id)
          }
            } else {
              this.$message.error('保存失败:' + res.message)
            }
          })
        }
      })
    },
  },
  watch: {},
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.page-main {
  .container {
    .content {
      margin-top: 20px;
      section {
        margin-bottom: 18px;
        .section-table {
          .add-btn {
            margin-left: 0;
            margin-bottom: 10px;
          }
          /deep/ .a-upload__input {
            display: none !important;
          }
        }
      }
    }
  }
  .tips-box {
    margin-top: 32px;
    .add-btn {
      width: 180px;
      height: 40px;
      line-height: 40px;
      background-color: #4095e4;
      border-radius: 2px;
    }
  }
}
/deep/ .el-upload__input {
  display: none !important;
}
/deep/.ant-form .ant-form-item-label {
  width: 150px;
}
</style>
<style lang="less" scoped>
/deep/ .el-upload__input {
  display: none !important;
}
/deep/.ant-form .ant-form-item-label {
  width: 150px !important;
}
/deep/.ant-form .ant-form-item-control-wrapper {
  display: inline-block;
  width: calc(100% - 150px) !important;
}
/deep/ #process-container {
  width: unset !important;
}
#process-container {
  background: #fff;
  padding: 40px 22px;
  width: auto;
  margin: 0 auto;
  -webkit-box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.15);
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.15);
}
</style>

